package com.ms.game.itembox;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.ms.game.itembox.container.ItemBasic;
import com.xpec.c4.service.module.common.ItemInfoManager;

public class ItemBasicAdapter  implements JsonSerializer<ItemBasic>, JsonDeserializer<ItemBasic>{

	@Override
	public ItemBasic deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
		String className = arg0.getAsJsonObject().get("itemClassName").getAsString();
		StringBuilder builder = new StringBuilder();
		builder.append(ItemInfoManager.ITEM_PACKAGE_NAME);
		builder.append(ItemInfoManager.DOT);
		builder.append(className);
		Class<?> itemClass = null;
		try {
			itemClass = Class.forName(builder.toString());
		} catch (ClassNotFoundException e) {

		}
		return arg2.deserialize(arg0, itemClass);
	}

	@Override
	public JsonElement serialize(ItemBasic arg0, Type arg1, JsonSerializationContext arg2) {
		return null;
	}

	

}
